import { FormatFunc, FormatMap, GetFormatMap } from "./types";

import "./data";
import "./execute-data";
import "./export-data";
import "./procedural-data";
import "./type-data";
import "./variable-data";

const formatMap: FormatMap = GetFormatMap();

export const FormatCode: FormatFunc = function (rule) {
	const type = rule[0] as string;
	const formatFunc = formatMap[type];
	if (formatFunc === undefined) {
		console.log(type, rule);
		throw new Error("未知数据，无法处理");
	}
	return formatFunc(rule, FormatCode);
}

export const FormatCodes = function (rules: any[]): string {
	return rules.map(info => FormatCode(info)).join("\n\n");
}

